<?php

class adminModel extends Model{
    public function admins($paging){
        $pagesize = 6;
        $sql = "select a.id,a.user,a.perm,b.type from admin a left join admintype b on a.perm = b.id limit ".($paging-1)*$pagesize.",{$pagesize}";
        $user = $this->link->selectByAll($sql);
        $sql = "select id from admin";
        $num = $this->link->count($sql);
        $pageNum = ceil($num/$pagesize);
        $userData = [];
        $userData['user'] = $user;
        $userData['page'] = $paging;
        $userData['allPage'] = $pageNum;
        return $userData;
    }
    public function aupdate($user,$prem,$pwd,$uid){
        $sql = "update admin set perm = $prem,user='{$user}',pwd='{$pwd}' where id = '{$uid}' ";
        $a = $this->link->update($sql);
        return $a;
    }

    public function remadmin($id){
        $sql = "delete from admin where id = {$id}";
        return $this->link->delete($sql);
    }
    public function adduser($user,$pwd,$prem){
        // $sql = "insert into admin(user,pwd,perm) values('$user','$pwd',$prem)";
        $sql = "insert into admin(user,pwd,perm) values('{$user}','{$pwd}',$prem)";
        $b = $this->link->insert($sql);
        if($b){
            // self::admins();
            return true;
        }else{
            return false;
        }
    }
}